﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicService
{
    public partial class MusicService:ITrackAlbumService
    {
        public bool addTrackAlbum(string albumID, string trackID)
        {
            bool flag = false;
            TrackAlbum trackAlbum = new TrackAlbum();
            try
            {
                trackAlbum.AlbumID = albumID;
                trackAlbum.TrackID = trackID;
                dc.TrackAlbums.InsertOnSubmit(trackAlbum);
                dc.SubmitChanges();
                flag = true;
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool removeTrackAlbum(string albumID, string trackID)
        {
            bool flag = false;
            try
            {
                TrackAlbum trackAlbum = dc.TrackAlbums.Single(tmp => tmp.AlbumID.Equals(albumID) &&
                    tmp.TrackID.Equals(trackID));
                if (trackAlbum != null)
                {
                    dc.TrackAlbums.DeleteOnSubmit(trackAlbum);
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool updateTrackAlbum(string albumID, string trackID)
        {
            bool flag = false;
            try
            {
                TrackAlbum trackAlbum = dc.TrackAlbums.Single(tmp => tmp.AlbumID.Equals(albumID) &&
                    tmp.TrackID.Equals(trackID));
                if (trackAlbum != null)
                {
                    trackAlbum.AlbumID = albumID;
                    trackAlbum.TrackID = trackID;
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public List<TrackAlbum> getAllTrackAlbum()
        {
            var list = from ta in dc.TrackAlbums select ta;
            return list.ToList();
        }

        public TrackAlbum getTrackAlbumByID(string albumID, string trackID)
        {
            TrackAlbum trackAlbum = dc.TrackAlbums.Single(tmp => tmp.AlbumID.Equals(albumID) &&
                    tmp.TrackID.Equals(trackID));
            return trackAlbum;
        }
    }
}